<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>discovery plugin | 微观世界</title>
    <meta name="generator" content="VuePress 1.5.0">
    <link rel="icon" href="/logo.jpg">
    <link rel="manifest" href="/manifest.json">
    <meta name="description" content="计算机软件 + 物联网 + 云计算项目开发、设计、咨询">
    <meta name="theme-color" content="#3eaf7c">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="msapplication-TileImage" content="/icons/msapplication-icon-144x144.png">
    <meta name="msapplication-TileColor" content="#000000">
    <link rel="preload" href="/assets/css/0.styles.6f9e93e5.css" as="style"><link rel="preload" href="/assets/js/app.520dc696.js" as="script"><link rel="preload" href="/assets/js/2.c11a0fe0.js" as="script"><link rel="preload" href="/assets/js/6.4a34bee7.js" as="script"><link rel="prefetch" href="/assets/js/10.e1be2428.js"><link rel="prefetch" href="/assets/js/11.de1b11c8.js"><link rel="prefetch" href="/assets/js/12.dfc23453.js"><link rel="prefetch" href="/assets/js/13.09541380.js"><link rel="prefetch" href="/assets/js/14.51d52b63.js"><link rel="prefetch" href="/assets/js/15.8259034b.js"><link rel="prefetch" href="/assets/js/16.247563a4.js"><link rel="prefetch" href="/assets/js/17.da2f0796.js"><link rel="prefetch" href="/assets/js/18.d0fc0deb.js"><link rel="prefetch" href="/assets/js/19.e93a1cc1.js"><link rel="prefetch" href="/assets/js/20.004d8702.js"><link rel="prefetch" href="/assets/js/21.e89ca0e5.js"><link rel="prefetch" href="/assets/js/22.38f46f4f.js"><link rel="prefetch" href="/assets/js/23.37daf9a7.js"><link rel="prefetch" href="/assets/js/3.be8d4a48.js"><link rel="prefetch" href="/assets/js/4.2b00d33c.js"><link rel="prefetch" href="/assets/js/5.c861589a.js"><link rel="prefetch" href="/assets/js/7.5a3e8270.js"><link rel="prefetch" href="/assets/js/8.0ebcc5ea.js"><link rel="prefetch" href="/assets/js/9.da64326c.js">
    <link rel="stylesheet" href="/assets/css/0.styles.6f9e93e5.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><!----> <span class="site-name">微观世界</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="成功案例" class="dropdown-title"><span class="title">成功案例</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/product/smart-home/" class="nav-link">
  智能家居
</a></li><li class="dropdown-item"><!----> <a href="/product/share-ark/" class="nav-link">
  共享快递柜
</a></li><li class="dropdown-item"><!----> <a href="/product/share-washing/" class="nav-link">
  共享洗衣机
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="开源项目" class="dropdown-title"><span class="title">开源项目</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/ws-cloud/gateway/" class="nav-link router-link-active">
  ws-cloud-gateway
</a></li></ul></div></div><div class="nav-item"><a href="/contact/" class="nav-link">
  联系我们
</a></div><div class="nav-item"><a href="/about/" class="nav-link">
  关于我们
</a></div><div class="nav-item"><a href="/link/" class="nav-link">
  友情链接
</a></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="成功案例" class="dropdown-title"><span class="title">成功案例</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/product/smart-home/" class="nav-link">
  智能家居
</a></li><li class="dropdown-item"><!----> <a href="/product/share-ark/" class="nav-link">
  共享快递柜
</a></li><li class="dropdown-item"><!----> <a href="/product/share-washing/" class="nav-link">
  共享洗衣机
</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="开源项目" class="dropdown-title"><span class="title">开源项目</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/ws-cloud/gateway/" class="nav-link router-link-active">
  ws-cloud-gateway
</a></li></ul></div></div><div class="nav-item"><a href="/contact/" class="nav-link">
  联系我们
</a></div><div class="nav-item"><a href="/about/" class="nav-link">
  关于我们
</a></div><div class="nav-item"><a href="/link/" class="nav-link">
  友情链接
</a></div> <!----></nav>  <ul class="sidebar-links"><li><section class="sidebar-group depth-0"><p class="sidebar-heading"><span>指南</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/ws-cloud/gateway/1.x/" class="sidebar-link">介绍</a></li><li><a href="/ws-cloud/gateway/1.x/getting-started.html" class="sidebar-link">快速上手</a></li></ul></section></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading"><span>插件</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/ws-cloud/gateway/1.x/plugin/" class="sidebar-link">介绍</a></li><li><a href="/ws-cloud/gateway/1.x/plugin/dev.html" class="sidebar-link">插件开发</a></li></ul></section></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading open"><span>官方插件</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/ws-cloud/gateway/1.x/plugin/official/discovery.html" class="active sidebar-link">discovery plugin</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/ws-cloud/gateway/1.x/plugin/official/discovery.html#说明" class="sidebar-link">说明</a></li><li class="sidebar-sub-header"><a href="/ws-cloud/gateway/1.x/plugin/official/discovery.html#参数" class="sidebar-link">参数</a></li><li class="sidebar-sub-header"><a href="/ws-cloud/gateway/1.x/plugin/official/discovery.html#设置" class="sidebar-link">设置</a></li></ul></li><li><a href="/ws-cloud/gateway/1.x/plugin/official/rewrite.html" class="sidebar-link">rewrite plugin</a></li><li><a href="/ws-cloud/gateway/1.x/plugin/official/tracing.html" class="sidebar-link">tracing plugin</a></li></ul></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="discovery-plugin"><a href="#discovery-plugin" class="header-anchor">#</a> discovery plugin</h1> <blockquote><p>discovery_plugin.lua</p></blockquote> <h2 id="说明"><a href="#说明" class="header-anchor">#</a> 说明</h2> <p>通过 <code>route.service_name</code> 查找上游服务节点，根据负载规则，转发到上游服务</p> <h2 id="参数"><a href="#参数" class="header-anchor">#</a> 参数</h2> <table><thead><tr><th>参数名</th> <th>类型</th> <th>默认值</th> <th>说明</th></tr></thead> <tbody><tr><td>discovery_node_not_found_resp</td> <td>string</td> <td>&quot;no server node start&quot;</td> <td>当没有查询到上游服务节点时返回的数据</td></tr></tbody></table> <h2 id="设置"><a href="#设置" class="header-anchor">#</a> 设置</h2> <ol><li>添加【路由】 -&gt; 【服务】映射</li></ol> <p><a href="http://localhost:10000/dashboard/#/gateway/routes" target="_blank" rel="noopener noreferrer">http://localhost:10000/dashboard/#/gateway/routes<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></p> <p><img src="/assets/img/routes-add.33603ff7.jpg" alt="添加理由"></p> <div class="language-json extra-class"><pre class="language-json"><code><span class="token comment">// props</span>
<span class="token punctuation">{</span>
  <span class="token property">&quot;discovery_node_not_found_resp&quot;</span><span class="token operator">:</span> <span class="token string">&quot;当没有发现服务节点时候返回的消息&quot;</span>
<span class="token punctuation">}</span>
</code></pre></div><ol start="2"><li>添加服务节点</li></ol> <p>大多数情况下，服务节点应该是在服务启动时自动注册，控制面板也提供了手动维护功能</p> <p><img src="/assets/img/service-add.53604a36.jpg" alt="添加服务节点"></p></div> <footer class="page-edit"><!----> <!----></footer> <div class="page-nav"><p class="inner"><span class="prev">
      ←
      <a href="/ws-cloud/gateway/1.x/plugin/dev.html" class="prev">
        插件开发
      </a></span> <span class="next"><a href="/ws-cloud/gateway/1.x/plugin/official/rewrite.html">
        rewrite plugin
      </a>
      →
    </span></p></div> </main></div><div class="global-ui"><!----></div></div>
    <script src="/assets/js/app.520dc696.js" defer></script><script src="/assets/js/2.c11a0fe0.js" defer></script><script src="/assets/js/6.4a34bee7.js" defer></script>
  </body>
</html>
